home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Demos / A.D. Software / OOFILE 1.3b4d6.sit / OOFILE 1.3b4d6 / OOFGraph 1.0b2 Demo / Application Source / GrTstApp.cp next >
Text File  |  1997-04-08  |  12KB  |  464 lines

  1. // ===========================================================================
  2. //    GrTstApp.cp                Derived heavily from the Dashboard Starter
  3. // ===========================================================================
  4. //
  5.  
  6. #include "GrTstApp.h"
  7.  
  8. #include <LApplication.h>
  9. #include <LGrowZone.h>
  10. #include <LWindow.h>
  11. #include <UDrawingState.h>
  12. #include <UMemoryMgr.h>
  13. #include <URegistrar.h>
  14. #include "math.h"
  15.  
  16. #include "oofGrPP.h"
  17. #include "oofGrphs.h"    // because we create bar & col graphs here
  18.  
  19. #ifdef OOF_SmartHeap
  20.     #include "smrtheap.hpp"
  21. #endif
  22.  
  23. // ===========================================================================
  24. //        * Main Program
  25. // ===========================================================================
  26.  
  27. void main()
  28. {
  29.                                     // Set Debugging options
  30.     SetDebugThrow_(debugAction_Alert);
  31.     SetDebugSignal_(debugAction_Alert);
  32.  
  33.     InitializeHeap(3);                // Initialize Memory Manager
  34.                                     // Parameter is number of Master Pointer
  35.                                     //   blocks to allocate
  36.     
  37.                                     // Initialize standard Toolbox managers
  38.     UQDGlobals::InitializeToolbox(&qd);
  39.     
  40.     new LGrowZone(20000);            // Install a GrowZone function to catch
  41.                                     //    low memory situations.
  42.                                     //    Parameter is size of reserve memory
  43.                                     //    block to allocated. The first time
  44.                                     //    the GrowZone function is called,
  45.                                     //    there will be at least this much
  46.                                     //    memory left (so you'll have enough
  47.                                     //    memory to alert the user or finish
  48.                                     //    what you are doing).
  49.     
  50.     GraphTestApp    theApp;            // Create instance of your Application
  51.     theApp.Run();                    //   class and run it
  52. }
  53.  
  54.  
  55. // ===========================================================================
  56. //        * GraphTestApp Class
  57. // ===========================================================================
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        * GraphTestApp
  61. // ---------------------------------------------------------------------------
  62. //    Constructor
  63.  
  64. void
  65. GraphTestApp::Initialize()
  66. {
  67. // DEFINE THE DATABASES
  68.  
  69.     dbConnect_ram        theDB;
  70.     dbStudent           Students;
  71.     dbOverlay            Overlay;
  72.     dbStudentOverlay    StudentsOverlay;
  73.     dbTemperature        Temperatures;
  74.     dbExports            Exports;
  75.     dbMath                Math;
  76. //    dbSales                Sales;
  77.  
  78.     theDB.newConnection("Databases");
  79.     Students.AddTestData();
  80.     Overlay.AddTestData();
  81.     StudentsOverlay.AddTestData();
  82.     Temperatures.AddTestData();
  83.     Exports.AddTestData();
  84.     Math.AddTestData();
  85. //    Sales.AddTestData();
  86.     
  87.     Students.setSortOrder(dbSorter() << Students.Name << Students.Subject);
  88.     
  89.     dbView Sview(Students, false);
  90.     Sview << Students.Name << Students.Subject << Students.Mark;
  91.     
  92.     Overlay.setSortOrder(Overlay.Name);
  93.  
  94.     dbView Oview(Overlay, false);
  95.     Oview << Overlay.LastYear;
  96.     
  97.     // NOTE: StudentOverlay is NOT sorted due to the necessary nature of the ordering
  98.     //       of the subject fields with regards to the overlay !
  99.     //
  100.     // NOTE ALSO: that even sorting by name is dangerous because the standard non-indexed
  101.     //            sort affects (reverses) the order of the other fields - by consequence
  102.     //            this graph is displayed with the students in a different order
  103.     dbView SviewOverlay(StudentsOverlay, false);
  104.     SviewOverlay << StudentsOverlay.Name << StudentsOverlay.Subject << StudentsOverlay.Mark;
  105.     
  106.     dbView Tview(Temperatures);
  107.     Tview << Temperatures.Day << Temperatures.Time << Temperatures.Temp;
  108.  
  109.     Exports.setSortOrder(dbSorter() << Exports.Year << Exports.Port);
  110.  
  111.     dbView Eview(Exports, false);
  112.     Eview << Exports.Year << Exports.Port << Exports.Value << Exports.Outcome;
  113.  
  114.     dbView Mview(Math);
  115.     Mview << Math.Name << Math.Xval << Math.Yval;
  116.  
  117. //    dbView Sales_view(Sales);
  118. //    Sales_view << Sales.Year << Sales.State << Sales.Sales;
  119.  
  120.     // OK - Let's get Powerplant to work
  121.     //    Register the functions to create our custom Pane classes
  122.     oofGraphWindow::RegisterClass();
  123.  
  124.     // Do the Stuff !
  125. //    oofGraphWindow::CreateColumnGraphWindow(this, &Sales_view, "Lots of\nSales");
  126.  
  127. // change some default settings
  128.     oofGraphDefaultSettings::settings()->hasYLabel(false);
  129.     oofGraphDefaultSettings::settings()->realTickLabelMask("%5.3f");
  130.  
  131. // create some graphs with default settings
  132.     oofGraphWindow::CreateStackedBarGraphWindow(this, &Tview, "Daily Temperatures");
  133.     oofGraphWindow::CreateStackedBarGraphWindowWithOverlay(this, &SviewOverlay, "Student Grade Average",
  134.         2 /* last 2 data series are overlaid */);
  135.     oofGraphWindow::CreateStackedBarGraphWindowWithOverlayView(this, &Sview, "Student Grade Average",&Oview);
  136.     oofGraphWindow::CreateOrdinalStackedBarGraphWindow(this, &Eview, "Port Profitability");
  137.     oofGraphWindow::CreateLineGraphWindow(this, &Sview, "Student Grade Average", 100);
  138.     oofGraphWindow::CreateXYGraphWindow(this, &Mview, "Some Transcendentals");
  139.  
  140. // create graphs with different settings
  141.     oofBarGraph* theBar = new oofBarGraph;
  142.     theBar->getLocalSettings()->hasValuesNextToBars(true);
  143.     oofGraphWindow::CreateWindow(this, theBar, &Tview, "Daily Temperatures");
  144.     
  145.     oofColumnGraph* theCol = new oofColumnGraph;
  146.     theCol->getLocalSettings()->hasValuesOverColumns(true);
  147.     oofGraphWindow::CreateWindow(this, theCol, &Sview, "Student Grade Average", 100);
  148. }
  149.  
  150.  
  151. // ---------------------------------------------------------------------------
  152. //        * ~GraphTest
  153. // ---------------------------------------------------------------------------
  154. //    Destructor
  155.  
  156. GraphTestApp::~GraphTestApp()
  157. {
  158. }
  159.  
  160.  
  161. // ---------------------------------------------------------------------------
  162. //        * ObeyCommand
  163. // ---------------------------------------------------------------------------
  164. //    Respond to commands
  165.  
  166. Boolean
  167. GraphTestApp::ObeyCommand(
  168.     CommandT    inCommand,
  169.     void        *ioParam)
  170. {
  171.     Boolean    cmdHandled = true;
  172.     
  173.     switch (inCommand) {
  174.     
  175.         default:
  176.             cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
  177.             break;
  178.     }
  179.     
  180.     return cmdHandled;
  181. }
  182.  
  183.  
  184. // ---------------------------------------------------------------------------
  185. //        * FindCommandStatus
  186. // ---------------------------------------------------------------------------
  187. //    Pass back status of a (menu) command
  188.  
  189. void
  190. GraphTestApp::FindCommandStatus(
  191.     CommandT    inCommand,
  192.     Boolean        &outEnabled,
  193.     Boolean        &outUsesMark,
  194.     Char16        &outMark,
  195.     Str255        outName)
  196. {
  197.     switch (inCommand) {
  198.     
  199.         default:
  200.             LApplication::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  201.                                 outMark, outName);
  202.             break;
  203.     }
  204. }
  205.  
  206.  
  207.  
  208.  
  209. // ===========================================================================
  210. //        * Student test data
  211. // ===========================================================================
  212. void dbStudent::Add(const char *name, const char *subject, const long mark)
  213. {
  214.     newRecord();
  215.     Name = name;
  216.     Subject = subject;
  217.     Mark = mark;
  218.     saveRecord();
  219. }
  220.  
  221.  
  222. void dbStudent::AddTestData()
  223. {
  224.     Add("Alice Chan", "Maths", 62);
  225.     Add("Alice Chan", "Social Studies", 72);
  226.     Add("Alice Chan", "English", 65);
  227.     Add("Alice Chan", "Science", 82);
  228.  
  229.     Add("Kathy Robins", "Maths", 82);
  230.     Add("Kathy Robins", "Social Studies", 54);
  231.     Add("Kathy Robins", "English", 44);
  232.     Add("Kathy Robins", "Science", 75);
  233.  
  234.     Add("Brett Baker", "Maths", 65);
  235.     Add("Brett Baker", "Social Studies", 78);
  236.     Add("Brett Baker", "English", 64);
  237.     Add("Brett Baker", "Science", 72);
  238.  
  239.     Add("Jack Smith", "Maths", 71);
  240.     Add("Jack Smith", "English", 56);
  241.     Add("Jack Smith", "Science", 81);
  242.     Add("Jack Smith", "Social Studies", 35);
  243. }
  244.  
  245. // ===========================================================================
  246. //        * overlay item for student data
  247. // ===========================================================================
  248. void dbOverlay::Add(const char *name, const long lastyear)
  249. {
  250.     newRecord();
  251.     Name = name;
  252.     LastYear = lastyear;
  253.     saveRecord();
  254. }
  255.  
  256.  
  257. void dbOverlay::AddTestData()
  258. {
  259.     Add("Alice Chan", 290);
  260.  
  261.     Add("Kathy Robins", 220);
  262.  
  263.     Add("Brett Baker", 270);
  264.  
  265.     Add("Jack Smith", 250);
  266. }
  267.  
  268. // ===========================================================================
  269. //        * Student test data with overlay item
  270. // ===========================================================================
  271. void dbStudentOverlay::Add(const char *name, const char *subject, const long mark)
  272. {
  273.     newRecord();
  274.     Name = name;
  275.     Subject = subject;
  276.     Mark = mark;
  277.     saveRecord();
  278. }
  279.  
  280.  
  281. void dbStudentOverlay::AddTestData()
  282. {
  283.     Add("Alice Chan", "Maths", 62);
  284.     Add("Alice Chan", "Social Studies", 72);
  285.     Add("Alice Chan", "English", 65);
  286.     Add("Alice Chan", "Science", 82);
  287.     Add("Alice Chan", "Last Year", 290);
  288.  
  289.     Add("Kathy Robins", "Maths", 82);
  290.     Add("Kathy Robins", "Social Studies", 54);
  291.     Add("Kathy Robins", "English", 44);
  292.     Add("Kathy Robins", "Science", 75);
  293.     Add("Kathy Robins", "Last Year", 220);
  294.  
  295.     Add("Brett Baker", "Maths", 65);
  296.     Add("Brett Baker", "Social Studies", 78);
  297.     Add("Brett Baker", "English", 64);
  298.     Add("Brett Baker", "Science", 72);
  299.     Add("Brett Baker", "Last Year", 270);
  300.  
  301.     Add("Jack Smith", "Maths", 71);
  302.     Add("Jack Smith", "Social Studies", 35);
  303.     Add("Jack Smith", "English", 56);
  304.     Add("Jack Smith", "Science", 81);
  305.     Add("Jack Smith", "Last Year", 250);
  306. }
  307.  
  308. // ===========================================================================
  309. //        * Math Test Data
  310. // ===========================================================================
  311.  
  312. void dbMath::Add(const char *name, const double x, const double y)
  313. {
  314.     newRecord();
  315.     Name = name;
  316.     Xval = x;
  317.     Yval = y;
  318.     saveRecord();
  319. }
  320.  
  321.  
  322. void dbMath::AddTestData()
  323. {
  324.     for(double theta=0;theta<6.3;theta=theta+0.157){
  325.         Add("Sine Wave (+1)",theta,(sin(theta)+1.0));
  326.         Add("Cosine Wave (+1)",theta,(cos(theta)+1.0));
  327.     }
  328. }
  329.  
  330.  
  331. // ===========================================================================
  332. //        * Temperature Test Data
  333. // ===========================================================================
  334.  
  335. void dbTemperature::Add(const char *day, const char *time, const long temp)
  336. {
  337.     newRecord();
  338.     Day = day;
  339.     Time = time;
  340.     Temp = temp;
  341.     saveRecord();
  342. }
  343.  
  344.  
  345. void dbTemperature::AddTestData()
  346. {
  347.     Add("Sun", "Day", 22);
  348.     Add("Sun", "Night", 12);
  349.     
  350.     Add("Mon", "Day", 24);
  351.     Add("Mon", "Night", 12);
  352.  
  353.     Add("Tue", "Day", 24);
  354.     Add("Tue", "Night", 10);
  355.     
  356.     Add("Wed", "Day", 27);
  357.     Add("Wed", "Night", 14);
  358.  
  359.     Add("Thu", "Day", 25);
  360.     Add("Thu", "Night", 12);
  361.     
  362.     Add("Fri", "Day", 22);
  363.     Add("Fri", "Night", 10);
  364.  
  365.     Add("Sat", "Day", 19);
  366.     Add("Sat", "Night", 8);
  367. }
  368.  
  369. // ===========================================================================
  370. //        * Exports Test Data
  371. // ===========================================================================
  372.  
  373. void dbExports::Add(const char *year, const char *port, const double value, const char *outcome)
  374. {
  375.     newRecord();
  376.     Year = year;
  377.     Port = port;
  378.     Value = value;
  379.     Outcome = outcome;
  380.     saveRecord();
  381. }
  382.  
  383.  
  384. void dbExports::AddTestData()
  385. {
  386.     Add("1993", "Fremantle", 12.3, "Profit");
  387.     Add("1993", "Geraldton", 8.1, "Break Even");
  388.     Add("1993", "Bunbury", 5.3, "Loss");
  389.  
  390.     Add("1994", "Fremantle", 16.1, "Break Even");
  391.     Add("1994", "Geraldton", 9.0, "Break Even");
  392.     Add("1994", "Bunbury", 10.9, "Profit");
  393.  
  394.     Add("1995", "Fremantle", 16.4, "Loss");
  395.     Add("1995", "Geraldton", 10.3, "Break Even");
  396.     Add("1995", "Bunbury", 10.8, "Break Even");
  397. }
  398.  
  399. /*
  400. // ===========================================================================
  401. //        * Sales Test Data
  402. // ===========================================================================
  403.  
  404. void dbSales::Add(const char *year, const char *state, const long sales)
  405. {
  406.     newRecord();
  407.     Year = year;
  408.     State = state;
  409.     Sales = sales;
  410.     saveRecord();
  411. }
  412.  
  413.  
  414. void dbSales::AddTestData()
  415. {
  416.     Add("1994", "WA", 200);
  417.     Add("1994", "SA", 145);
  418.     Add("1994", "QLD", 65);
  419.     Add("1994", "VIC", 120);
  420.     Add("1994", "NSW", 180);
  421.     Add("1994", "TAS", 55);
  422.     Add("1994", "NT", 80);
  423.     Add("1994", "ACT", 40);
  424.     
  425.     Add("1994", "WA2", 200);
  426.     Add("1994", "SA2", 145);
  427.     Add("1994", "QLD2", 65);
  428.     Add("1994", "VIC2", 120);
  429.     Add("1994", "NSW2", 180);
  430.     Add("1994", "TAS2", 55);
  431.     Add("1994", "NT2", 80);
  432.     Add("1994", "ACT2", 40);
  433.  
  434.     Add("1994", "WA3", 200);
  435.     Add("1994", "SA3", 145);
  436.     Add("1994", "QLD3", 65);
  437.     Add("1994", "VIC3", 120);
  438.     Add("1994", "NSW3", 180);
  439.     Add("1994", "TAS3", 55);
  440.     Add("1994", "NT3", 80);
  441.     Add("1994", "ACT3", 40);
  442.  
  443.     Add("1994", "WA4", 200);
  444.     Add("1994", "SA4", 145);
  445.     Add("1994", "QLD4", 65);
  446.     Add("1994", "VIC4", 120);
  447.     Add("1994", "NS4", 180);
  448.     Add("1994", "TAS4", 55);
  449.     Add("1994", "NT4", 80);
  450.     Add("1994", "ACT4", 40);
  451.  
  452.     Add("1994", "WA5", 200);
  453.     Add("1994", "SA5", 145);
  454.     Add("1994", "QLD5", 65);
  455.     Add("1994", "VIC5", 120);
  456.     Add("1994", "NS5", 180);
  457.     Add("1994", "TAS5", 55);
  458.     Add("1994", "NT5", 80);
  459.     Add("1994", "ACT5", 40);
  460. }
  461.  
  462. */
  463.  
  464.